<template>
  <div>
    <!-- header -->
    <div class="hero-header" style="max-width: 100vw; overflow-x: hidden; min-height: 120px;">
      <div class="header-content" style=" max-width: 100%;margin-left: 50px; display: flex; align-items: center;">
        <span class="header-logo" style="width: 100px; height: 100px;">
          <img style="display: inline-block; width: 100px; height: 100px;" src="/src/pages/index/static/logo.png"
            alt="">
        </span>
        <span class="hear-text" style="width: 300px;">
          <div style=" margin-top: 10px;display: inline-block; color: #215eba; font-size: 16px; font-weight: 700; ">
            区块链安全保障技术政务平台
          </div>
          <div class="hearderPitem" style="width: 500px; color: #3172d4; font-size: 28px; font-weight: 800;">
            社会保障助老多功能平台
          </div>
        </span>
        <img style="margin-left: 10%; height: 39px; zoom: 2;" src="/src/pages/index/static/flag4.png" alt="">
        <!-- <img style="margin-left: 7%; height: 40px;" src="/src/pages/index/static/flag.png" alt="">
        <img style="margin-left: 5%; height: 40px;" src="/src/pages/index/static/flag2.png" alt=""> -->
        <!-- <div class="header-right" style="float: right;">123456</div> -->
        <div class="button" @click="toHome()"
          style="margin-right: 5%;background: #fff; border: 1px solid #5771d1; color: #5771d1; position: absolute; right: 20px; top: 28px; z-index: 999; padding: 8px 16px; cursor: pointer; border-radius: 4px; transition: background-color 0.3s, color 0.3s;">
          首页
        </div>
        <div class="button" @click="loginOff()"
          style="background: #fff; border: 1px solid #5771d1; color: #5771d1; position: absolute; right: 20px; top: 28px; z-index: 999; padding: 8px 16px; cursor: pointer; border-radius: 4px; transition: background-color 0.3s, color 0.3s;">
          注销
        </div>
      </div>
    </div>

    <div class="common-layout">
      <el-container>
        <el-aside width="300px" style="height: 100%;">
          <div style="height: auto;">
            <el-menu class="el-menu-vertical-demo" default-active="1" text-color="#545c64" @open="handleOpen"
              @close="handleClose">
              <!-- 1  雇主-->
              <el-sub-menu index="1" v-show="confirmEmployer">
                <template #title>
                  <el-icon>
                    <Avatar />
                  </el-icon>
                  <span>雇主功能</span>
                </template>
                <el-menu-item index="1" icon="Document" @click="navigateToPage('/user/index/employer')">
                  <span>雇主保险详情</span>
                </el-menu-item>

                <!-- <el-menu-item index="1-1" @click="navigateToPage('/user/index/welcome')">欢迎页</el-menu-item> -->
              </el-sub-menu>
              <!-- 2 员工-->
              <el-sub-menu index="2" v-show="confirmEmployee">
                <template #title>
                  <el-icon>
                    <Avatar />
                  </el-icon>
                  <span>员工功能</span>
                </template>
                <el-menu-item index="1-1" icon="User" @click="navigateToPage('/user/index/profile')">
                  <span>个人中心</span>
                </el-menu-item>
                <el-menu-item index="2-1" icon="Location" @click="navigateToPage('/user/index/employee')">
                  <span>个人保险信息</span>
                </el-menu-item>
                <el-menu-item index="2-2" icon="Location" @click="navigateToPage('/user/index/claim')">
                  <span>理赔信息</span>
                </el-menu-item>
                <el-sub-menu index="2-3">
                  <template #title>独立页面访问</template>
                  <el-menu-item index="2-3-1" @click="navigateToPage('/user/standalone/profile')">
                    <span>独立个人中心</span>
                  </el-menu-item>
                  <el-menu-item index="2-3-2" @click="navigateToPage('/user/standalone/employee')">
                    <span>独立保险信息</span>
                  </el-menu-item>
                  <el-menu-item index="2-3-3" @click="navigateToPage('/user/standalone/claim')">
                    <span>独立理赔信息</span>
                  </el-menu-item>
                </el-sub-menu>
              </el-sub-menu>
              <!-- 3 社保-->
              <el-sub-menu index="3" v-show="confirmBureau">
                <template #title>
                  <el-icon>
                    <Avatar />
                  </el-icon>
                  <span>社保局功能</span>
                </template>
                <el-menu-item index="3-1" icon="Setting" @click="navigateToPage('/user/index/bureau')">
                  <span>保险申请表信息</span>
                </el-menu-item>
                <el-sub-menu index="3-2">
                  <template #title>社保数据统计分析</template>
                  <el-menu-item index="3-2-1" icon="Setting" @click="navigateToPage('/user/index/bureau/dataAnalyze')">
                    <span>参保信息</span>
                  </el-menu-item>
                  <el-menu-item index="3-2-2" icon="Setting" @click="navigateToPage('/user/index/bureau/aiAnalyze')">
                    <span>AI数据分析</span>
                  </el-menu-item>
                </el-sub-menu>

              </el-sub-menu>
              <!-- 4 管理员-->
              <el-sub-menu index="4" v-show="confirmAdmin">
                <template #title>
                  <el-icon>
                    <Avatar />
                  </el-icon>
                  <span>管理员功能</span>
                </template>
                <el-menu-item index="4" icon="Setting" @click="navigateToPage('/user/index/employerSearchBureau')">
                  <span>社保局信息</span>
                </el-menu-item>
                <el-menu-item index="4-1" @click="navigateToPage('/user/index/admin')">公司保险查看</el-menu-item>
                <el-menu-item index="4-2" @click="navigateToPage('/user/index/adminSearchEmployee')">员工保险查看
                </el-menu-item>
                <el-menu-item index="4-3" icon="Warning" @click="navigateToPage('/user/index/risk-management')">
                  <span>风险管控</span>
                </el-menu-item>
              </el-sub-menu>
            </el-menu>
          </div>
        </el-aside>
        <el-main style="height: calc(100vh - 120px); overflow-y: auto;">
          <router-view></router-view>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import { ElNotification } from 'element-plus'
// 导入图标组件
import {
  Avatar,
  Warning
} from '@element-plus/icons-vue'

const router = useRouter();

// 权限判断
const confirmEmployer = ref(false) //2
const confirmEmployee = ref(false) //1
const confirmBureau = ref(false)   //3
const confirmAdmin = ref(false)    //0


const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};

const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
// 返回首页
const toHome = () => {
  router.push('/index/top')
}

// 注销功能
const loginOff = () => {
  localStorage.removeItem('senderAddress')
  localStorage.removeItem('sponsorName')
  ElNotification({
    title: '成功',
    message: '注销成功',
    type: 'success',
  })
  router.push('/')
}

// 路由跳转方法
const navigateToPage = (route: string) => {
  router.push(route);
};

//confirmAuth
const confirmAuth = () => {
  const type = localStorage.getItem('type')
  if (type) {
    if (parseInt(type) === 0) {
      confirmAdmin.value = true;
      //test
      confirmEmployee.value = true;
      confirmEmployer.value = true
      confirmBureau.value = true
    }
    if (parseInt(type) === 1) {
      confirmEmployee.value = true;
    }
    if (parseInt(type) === 2) {
      confirmEmployer.value = true
    }
    if (parseInt(type) === 3) {
      confirmBureau.value = true
    }
  }

}

onMounted(() => {
  confirmAuth()
})
</script>

<style scoped>
/* 头部背景色和渐变效果 */
.hero-header {
  background: var(--primary-gradient);
  position: relative;
  overflow: hidden;
}

.hero-header::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 200%;
  height: 100%;
  background: linear-gradient(90deg,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.1) 50%,
      rgba(255, 255, 255, 0) 100%);
  animation: shine 3s infinite;
}

@keyframes shine {
  100% {
    left: 100%;
  }
}

.header-content {
  display: flex;
  align-items: center;
}

.header-logo img {
  border-radius: 50%;
}

.hear-text {
  margin-left: 20px;
}

.hearderPitem {
  font-size: 28px;
  font-weight: 800;
  color: white;
}

.button {
  background: var(--primary-gradient);
  border: none;
  box-shadow: 0 4px 15px rgba(33, 94, 186, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(33, 94, 186, 0.4);
  background: var(--hover-gradient);
}

.button::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.1);
  opacity: 0;
  transition: opacity 0.3s;
}

.button:hover::after {
  opacity: 1;
}

/* 侧边栏菜单样式优化 */
.el-menu {
  border-right: none;
}

.el-menu-item {
  transition: all 0.3s;
  position: relative;
}

.el-menu-item:hover {
  background: linear-gradient(90deg, rgba(33, 94, 186, 0.1) 0%, transparent 100%);
  transform: translateX(8px);
}

.el-menu-item::before {
  content: "";
  position: absolute;
  left: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 0;
  background: var(--accent-color);
  transition: height 0.3s;
}

.el-menu-item:hover::before {
  height: 60%;
}

.common-layout {
  height: auto;
  min-height: 82vh;
}

.el-aside {
  padding: 20px;
}

.el-main {
  padding: 20px;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  transition: all 0.3s;
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border: 2px solid transparent;
  background: linear-gradient(135deg, #215eba, #4CAF50) border-box;
  background: -webkit-linear-gradient(#fff 0 0) padding-box,
    linear-gradient(#fff 0 0);
  mask-composite: exclude;
  transition: opacity 0.3s;
  opacity: 0;
}

.card:hover::after {
  opacity: 1;
}

:root {
  --primary-gradient: linear-gradient(135deg, #215eba 0%, #3172d4 50%, #6a8de6 100%);
  --hover-gradient: linear-gradient(135deg, #1a4a8f 0%, #2b5fb8 50%, #5c7bd9 100%);
  --accent-color: #4CAF50;
  --text-primary: #2c3e50;
  --text-secondary: #7f8c8d;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  letter-spacing: -0.02em;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #215eba;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    margin-left: 0;
  }

  .button {
    position: static;
    margin: 10px 0;
  }

  .el-aside {
    width: 100% !important;
    height: auto;
  }
}
</style>
